package com.slunk.platforms;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;

/**
 * This class will be responsible for rendering 
 * a background sprite on which the label will be laid on top of to give the effect the label is being
 * highlighted.
 * @author Cthulhu
 *
 */
public class SLabelHighlight extends SLabel {
	private Sprite highlightSprite;
	//No need to have two sprite's, just change the color of the highlight sprite. This will have the alpha channel at 1
	private Color onColor;
	//This will have the alpha channel at 0
	private Color offColor;
	
	/**
	 * The constructor for the SLabelHighlight class.
	 * 
	 * @param choice String text for the label
	 * @param x Float value for the x position
	 * @param y Float value for the y position
	 * @param width Float width of the label
	 * @param highlightSprite Sprite for the highlight 
	 */
	public SLabelHighlight(String choice, float x, float y, float width, Sprite highlightSprite) {
		super(choice, x, y, width);
		this.highlightSprite = highlightSprite;		
		onColor = this.highlightSprite.getColor();
		offColor = new Color(onColor.r,onColor.g,onColor.b,0.0f);
		unhighlightLabel();
	}
	
	/**
	 * Helper function for drawing the label. Will only draw the highlight if the label is displayed.
	 */
	public void drawSelf(SpriteBatch batch) {
		super.drawSelf(batch);
		if (isDisplaying) {
			TextBounds bounds = getBounds();
			highlightSprite.setBounds(x, y, bounds.width, -bounds.height);
			highlightSprite.draw(batch);
		}
	}
	
	/**
	 * Overrided function that checks with parent class if it contains mouse position. If this object
	 * contains the mouse position, then display the on highlight color. Otherwise display the
	 * un-highlight color.
	 */
	@Override
	public boolean containsMousePosition(float x, float y) {
		boolean touched = super.containsMousePosition(x,y);
		if (touched) {
			highlightLabel();
		} else {
			unhighlightLabel();
		}
		return touched;
	}
	
	/**
	 * Set the alpha channel of highlight sprite to 1.0f
	 */
	public void highlightLabel() {
		highlightSprite.setColor(onColor);
	}
	
	/**
	 * Set the alpha channel of highlight sprite to 0.0f
	 */
	public void unhighlightLabel() {
		highlightSprite.setColor(offColor);
	}
}
